package org.vineatoum.bo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.vineatoum.etats.Recolte;
import org.vineatoum.etats.VinAbstract;
import org.vineatoum.exception.VinengineException;


public class Plantation extends VinAbstract{
	private static Set<Plantation> plantations = new HashSet<Plantation>();
	
	private float unharvestPercent = 100;
	List<Recolte> recoltes = new ArrayList<Recolte>();
	
	private String id;
	

	public Plantation(String id) {
		plantations.add(this);
		this.id = id;
	}

	public String getId() {
		return id;
	}
	
	public float getUnharvestPercent() {
		return unharvestPercent;
	}

	protected void setUnharvestPercent(float unharvestPercent) throws VinengineException {
		if(unharvestPercent<=100 || unharvestPercent>=0)
		{
			this.unharvestPercent = unharvestPercent;
		}
		else
		{
			throw new VinengineException("unharvestPercent  = "+unharvestPercent+". Have to be <=100 and >=0");

		}
	}
	
	public void newHarvest(){
		Recolte recolte = new Recolte(this, "benneId");
		recoltes.add(recolte);
	}
	
	
	public Recolte newHarvest(float harvestPercentage) throws VinengineException {
		if(this.unharvestPercent - harvestPercentage >=0) {
			Recolte temp = new Recolte(this);
			this.setUnharvestPercent(this.unharvestPercent - harvestPercentage);
			return temp;
		} else {
			throw new VinengineException("Can't create new Raisin. Percentage to harvest is too big");
		}
	}
	
//	@Override
//	public void getTracking() {
//		System.out.println(this);
//	}
	
	@Override
	public String toString() {
		String out = "------ Plantation " + id;
		return out;
	}

	public static Set<Plantation> getCollection() {
		return plantations;
	}

}
